package com.gdk.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.gdk.service.ArticleService;
import com.gdk.service.FairService;
import com.gdk.service.HXService;
import com.gdk.service.LoginService;
import com.gdk.service.NavigationService;
import com.gdk.service.PromotionService;
import com.gdk.service.ShopService;
import com.gdk.utils.XVDateUtils;

/**
 * 核销controller
 * */

@Controller
public class HXController {
	
	@Autowired
    private HXService hxService;

	@Autowired
    private FairService fairService;
	
	
	
	/**
	 * 查询所有会议
	 * */
	@RequestMapping("/findAllHXLog.do")
	public String findAllHXLog(@RequestParam Map<String,Object> map, HttpServletRequest request) {
		
		System.out.println("查询  :  "+map);
		
	
		int page_num = 20;
		int number = 1;
		int size = 0;
		List<Map<String, Object>> allHXLog = null;
	
	
		if(!("".equals(map.get("page_num")) || map.get("page_num") == null)) {
			page_num = Integer.parseInt(map.get("page_num").toString());
		}
		
		map.put("page_num", page_num);
	//	System.out.println("所有订单查询"+map);
		if(map.get("number") != null && !"".equals(map.get("number")) ) {
			number = Integer.valueOf(map.get("number").toString());
		}
		int pageNum = number;
	//	System.out.println("pageNum  :  "+pageNum);
		map.remove("number");
		//map.put("number", number);
	//	System.out.println("map  : "+map);
		
		String nnnm = page_num+"";
	//	System.out.println("nnnm  :"+nnnm);
		double page_float = Double.parseDouble(nnnm);
		
		
		int itemCount = hxService.findAllHXLog(map).size();
		
		map.put("allHXLogItem",itemCount);
		
		
		
		List<Map<String, Object>> allFair = fairService.findAllFair(map);
		
		
		
		size = (int) Math.ceil(itemCount/page_float);
		//size = (int) Math.ceil(orderService.doSelectAllOrder(map).size()/10.0f);
		//System.out.println("分页数量  : "+size);
		if (size == 0) {
			request.setAttribute("allFair", allFair);
			request.setAttribute("msg", "没符合的数据");
			return "jsp/hx/hx-list";
		}
		if (number == 1) {
			map.put("number", 0);
		} else {
			map.put("number",(number-1)*page_num);
		}
//						System.err.println("分页数据    :  "+map);

		//分页所有订单
		allHXLog = hxService.findAllHXLog(map);

		
		//所有类型
		map.put("number", pageNum);
		map.put("sumNumber", size);
		//model.addAttribute("page", map);
		request.setAttribute("page",map);
		System.out.println("page_map map内含  :   "+map);
		
		//List<Map<String, Object>> supplyHXCode = orderService.selectSupplyHXCode(map);
	
		for (Map<String, Object> map2 : allHXLog) {
			if(map2.get("sign_in_time") != null) {
				int p = Integer.valueOf(map2.get("sign_in_time").toString());
				if(p != 0) {
					map2.put("sign_in_time", XVDateUtils.MillisFormat(p));	
				}
			}
			
			
		}
		request.setAttribute("allFair", allFair);
		/*List<Map<String, Object>> allModule = navigationService.selectAllModule();
		request.setAttribute("allModule", allModule);*/
		request.setAttribute("allHXLog",allHXLog);
		return "jsp/hx/hx-list";
	}
	
	
	
	
	
	/**
	 * 修改核销状态
	 * */
	@ResponseBody
	@RequestMapping("/updateHXLogStatus.do")
	public int updateHXLogStatus(@RequestParam Map<String,Object> map, HttpServletRequest request) {
		System.out.println("文章 : "+map);
		int shop =  hxService.updateHXLog(map);
		return shop;
	}


}